# coding=utf-8
import re
import socket

import feedparser
import pymongo

# conn = pymongo.MongoClient('localhost', 27017)
# dbRSS = conn['dbRSSs']
# rss = dbRSS['rss']
# # rs = rss.find({"categories" : {'$regex':'["科技"]'}})
# # rs = rss.find({"categories":{'$elemMatch': {"科技"}}})
# # rs = rss.find({"categories" : {'$in':[u'科技',re.compile(u',')]}})
# rs = rss.find({"categories" : {'$in':[u'科技']}})
# for a in rs:
#     print a.get("categories")
#
# print a
# conn = pymongo.MongoClient('localhost', 27017)
# db = conn['dbLuoo']
# collec = db['musics']
# pagesize = 10
# pageindex = 0
# data = collec.find({}).sort('_id', 1).skip(pageindex * pagesize).limit(pagesize)
# print data[20]
# for i in range(0, 100, 10):
#     print data.count(with_limit_and_skip=)
#collec.update({}, {'$rename': {"vol_date": "date"}}, False, True)

#collec.update({}, {'$set': {'type': 2}}, upsert=False, multi=True)
#ou = collec.find().sort("_id")
# a = []
# for i in range(0, 100, 10):
#     a.append(ou[i])
# print len(a)


# dbRSS = conn['dbRSSs']
# rss = dbRSS['rss']
# ot = rss.find_one({"_id": "55a4ad749a918f2310ab0617"})
# title = ot.get("title")
# favicon = ot.get("avatar")
# url = ot.get("url")
# feed = feedparser.parse(url)
# entries = feed.entries
# for entry in entries:
#     print entry.title
#     keys = entry.keys()
#     if "content" in keys:
#         print entry.content[0].value
#     print entry.summary
#     print entry.published
# print title, favicon, url


conn = pymongo.MongoClient('localhost', 27017)

db = conn['Prometheus']
collec_music = db['musics']
collec_rss = db['rss']


rsss = collec_rss.find_one({'_id': "556d0d2af947df8440f8d032"})
print rsss